/**
 * 打包制作工具，用于生产 MANIFEST.MF文件
 */
package ms.core.serv.tool;

import java.io.File;
import java.util.Date;

import ms.core.tool.DateTimeTool;
import ms.core.tool.SysTool;

public class ManifestFileTool {
	// 日志内容
	private static void traceLog(String log) {
		System.out.println(DateTimeTool.dateToDateTimeString(new Date())+" "+ManifestFileTool.class.getName()+"=>" +log);
	}

	public static void makeManifestFile(String mainClassName, String libPath, String saveToFile) {
		try {
			traceLog("开始遍历 "+libPath+"目录下文件...");

			StringBuffer content = new StringBuffer();
			content.append("Manifest-Version: 1.0"+System.lineSeparator());
			content.append("Main-Class: "+mainClassName+System.lineSeparator());
			content.append("Class-Path: "+System.lineSeparator());
			File libs = new File(libPath);
			String[] files = libs.list();
			for(String file: files) {
				content.append("  lib/"+file+" "+System.lineSeparator());
			}
			content.append(System.lineSeparator());
			SysTool.writeTextFile(saveToFile, content.toString(), "utf8");
			System.out.println(content);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		makeManifestFile("ms.core.serv.system.Application","E:\\JavaWork\\helios.net\\helios-serv\\bin\\lib","E:\\JavaWork\\helios.net\\helios-serv\\bin\\META-INF(helios-serv)\\MANIFEST.MF");
	}
}
